package com.theme.passport.controller.trade;

import com.theme.common.mvc.utils.PageUtils;
import com.theme.common.mvc.view.R;
import com.theme.passport.entity.theme.UserPayOrderEntity;
import com.theme.passport.service.theme.UserPayOrderService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;



/**
 * 用户内购订单记录
 *
 * @author live
 * @email 870459550@qq.com
 * @date 2023-02-22 08:48:28
 */
@RestController
@RequestMapping("trade/user-order")
public class UserOrderController {
    @Autowired
    private UserPayOrderService tabUserPayOrderService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("trade:user-order:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tabUserPayOrderService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("trade:user-order:info")
    public R info(@PathVariable("id") Long id){
		UserPayOrderEntity tabUserPayOrder = tabUserPayOrderService.getById(id);

        return R.ok().put("userOrder", tabUserPayOrder);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("trade:user-order:save")
    public R save(@RequestBody UserPayOrderEntity tabUserPayOrder){
        tabUserPayOrder.setCreated(new Date());
		tabUserPayOrderService.save(tabUserPayOrder);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("trade:user-order:update")
    public R update(@RequestBody UserPayOrderEntity tabUserPayOrder){
        tabUserPayOrder.setUpdated(new Date());
		tabUserPayOrderService.updateById(tabUserPayOrder);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("trade:user-order:delete")
    public R delete(@RequestBody Long[] ids){
		tabUserPayOrderService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
